package com.boot.web.serviceImpl;

import com.boot.exception.BusinessException;
import com.boot.web.dao.ButtonPowerDao;
import com.boot.web.entity.ButtonPower;
import com.boot.web.service.ButtonPowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.boot.base.serviceImpl.BaseServiceImpl;

import java.util.Date;

/**
 * 按钮权限信息业务层接口实现
 * @author 【zhouJie】
 * @date 2019-12-05 17:31:35
 */
@Service
public class ButtonPowerServiceImpl extends BaseServiceImpl<ButtonPower> implements ButtonPowerService {

    @Autowired
    private ButtonPowerDao buttonPowerDao;

    @Override
    public ButtonPower getButtonPowerBySign(String sign) {
        return buttonPowerDao.queryButtonPowerBySign(sign);
    }

    @Override
    public int saveButtonPower(ButtonPower buttonPower) {
        ButtonPower bp = buttonPowerDao.queryButtonPowerBySign(buttonPower.getSign());
        if (bp == null) {
            buttonPower.setUpdateTime(new Date());
            return buttonPowerDao.save(buttonPower);
        } else {
            throw new BusinessException("按钮权限[系统标识]已存在");
        }
    }

}
